package com.lbg.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lbg.drug.dto.Admindto;
import com.lbg.drug.dto.Adminupdate;
import com.lbg.drug.entity.Admin;
import com.lbg.drug.mapper.AdminMapper;
import com.lbg.drug.service.AdminService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lbg
 * @since 2022-04-26
 */
@Service
public class  AdminServiceImpl implements AdminService {


    @Autowired
    private AdminMapper adminMapper;


    @Override
    public Admin getLogin(Admindto admindto) {
        Admin admin = new Admin();

        BeanCopier beanCopier = BeanCopier.create(Admindto.class, Admin.class, false);
        beanCopier.copy(admindto,admin,null);

        QueryWrapper<Admin> a = new QueryWrapper<>();
        a.eq("user_id",admin.getUserId()).eq("password",admin.getPassword());
        return adminMapper.selectOne(a);


    }

    @Override
    public void update(Adminupdate adminupdate) {

        Admin admin = new Admin();

        BeanCopier beanCopier = BeanCopier.create(Adminupdate.class, Admin.class, false);
        beanCopier.copy(adminupdate,admin,null);

        QueryWrapper<Admin> a = new QueryWrapper<>();
        a.eq("user_id",adminupdate.getUserId());
        adminMapper.update(admin,a);

    }

    @Override
    public void add(Adminupdate adminupdate) {

        Admin admin = new Admin();

        BeanCopier beanCopier = BeanCopier.create(Adminupdate.class, Admin.class, false);
        beanCopier.copy(adminupdate,admin,null);
        admin.setUserType("普通用户");
        adminMapper.insert(admin);

    }
}
